import type { ConsultType } from '@/enums'
import type { Consult, ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'consult',
  () => {
    // 问诊记录数据
    const consult = ref({} as PartialConsult)

    // 修改问诊类型的方法
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }

    // 修改医院类型的方法
    const setIllnessType = (illnessType: 0 | 1) => {
      consult.value.illnessType = illnessType
    }

    // 修改科室类型的方法
    const setDep = (depId: string) => {
      consult.value.depId = depId
    }

    // 修改病情描述信息的方法
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    // 修改患者的方法
    const setPatient = (patientId: string) => {
      consult.value.patientId = patientId
    }

    // 清空问诊记录信息的方法
    const clear = () => {
      consult.value = {}
    }

    return { consult, setType, setIllnessType, setDep, setIllness, setPatient, clear }
  },
  {
    persist: true
  }
)
